package 每个字符最多出现两次的最长子字符串3090;

public class Solution {
    public int maximumLengthSubstring(String s) {
        int[] arr = new int[26];
        int min = 0;
        int left = 0;
        int right = 0;
        while (right < s.length()) {
            if (arr[s.charAt(right) - 'a'] == 2) {
                arr[s.charAt(left) - 'a']--;
                left++;
            }else {
                arr[s.charAt(right) - 'a']++;
                min = Math.max(min, right - left + 1);
                right++;
            }
        }
        return min;
    }
}
